// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava.model;

import org.objectweb.asm.Opcodes;

public class ClassDefinition extends JavaClass {

	private int access;
	
	private String signature;
	
	private JavaClass superClass;
	
	private String packageName;
	
	private JavaClass outerClass;
	
	public ClassDefinition(
			String internalName,
			int access,
			String signature,
			JavaClass superClass,
			String packageName) {
		super(internalName);
		this.access = access;
		this.signature = signature;
		this.superClass = superClass;
		this.packageName = packageName;
	}
	
	public int getAccess()
	{
		return this.access;
	}
	
	public String getSignature()
	{
		return this.signature;
	}
	
	public JavaClass getSuperClass()
	{
		return this.superClass;
	}
	
	public String getPackageName()
	{
		return this.packageName;
	}
	
	public boolean isInterface()
	{
		return (access & Opcodes.ACC_INTERFACE) != 0;
	}

	public boolean isAbstract()
	{
		return (access & Opcodes.ACC_ABSTRACT) != 0;
	}
	
	public boolean isFinal()
	{
		return (access & Opcodes.ACC_FINAL) != 0;
	}
	
	public boolean isPublic()
	{
		return (access & Opcodes.ACC_PUBLIC) != 0;
	}
	
	public boolean isSuper()
	{
		return (access & Opcodes.ACC_SUPER) != 0;
	}
	
	public boolean isAnnotation()
	{
		return (access & Opcodes.ACC_ANNOTATION) != 0;
	}
	
	public boolean isEnum()
	{
		return (access & Opcodes.ACC_ENUM) != 0;
	}
	
	public boolean isSynthetic()
	{
		return (access & Opcodes.ACC_SYNTHETIC) != 0;
	}
	
	public JavaClass getOuterClass() {
		return this.outerClass;
	}
	
	public void setOuterClass(JavaClass javaClass) {
		this.outerClass = javaClass;
	}
	
	@Override
	public boolean equals(Object o) {
		if (!this.getClass().isInstance(o))
			return super.equals(o);
		ClassDefinition other = (ClassDefinition)o;
		return super.equals(o) && this.access == other.access &&
			this.superClass.equals(other.superClass) &&
			this.packageName.equals(other.packageName) &&
			(this.signature == null ? other.signature == null : this.signature.equals(other.signature)) &&
			(this.outerClass == null ? other.outerClass == null : this.outerClass.equals(other.outerClass));
	}
	
	@Override
	public String toString()
	{
		return super.toString() + " " + this.access + " " + this.signature;
	}
}
